package com.link2room.rodimus.controller.inside;


import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.rodimus.dto.param.inside.CreateMemberByMobileParamDto;
import com.link2room.rodimus.dto.param.inside.MemberBaseInsideParamDto;
import com.link2room.rodimus.facade.IMemberInsideFacadeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by LN on 2017/6/21.10:48
 */
@Api(tags = "会员相关")
@RestController
@RequestMapping("/in/members")
public class MemberController {
    @Resource
    private IMemberInsideFacadeService memberInsideFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto getMember(
            @RequestParam(name = "openid",required = false) String openid,
            @RequestParam(name = "mobile",required = false) String mobile
    ) throws Exception {
        MemberBaseInsideParamDto paramDto = new MemberBaseInsideParamDto();
        paramDto.setOpenid(openid);
        paramDto.setMobile(mobile);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        resDto.setResultInfo(memberInsideFacadeService.selectMemberBase(paramDto));
        return resDto;
    }

    @RequestMapping(value = "/checkAndCreate",method = RequestMethod.POST)
    public BaseResultDto checkAndCreate(@RequestBody CreateMemberByMobileParamDto paramDto) throws Exception {
        memberInsideFacadeService.checkAndCreateNewMemberByMobileIfNotExit(paramDto);
        BaseResultDto resDto = new BaseResultDto();
        resDto.setResultCode(0);
        return resDto;
    }

}
